<template>
  <div>
    <cart-mode ref="cartModle" buttonText="确 定" @isClossing="updateCart"  :height="'auto'">
      <add-cart-for-proce v-if="commodityInfo" ref="addCartForProce"  @Closing="hideShade"
                          :commodityInfor="commodityInfo">
      </add-cart-for-proce>
    </cart-mode>
    <cart-mode ref="cartFoodModle" buttonText="确 定(堂食)" @isClossing="updateCart"  :height="'auto'">
      <add-cart-for-food-proce v-if="commodityInfo" ref="addCartForFoodProce"  @Closing="hideShade"
                          :commodityInfor="commodityInfo">
      </add-cart-for-food-proce>
    </cart-mode>

  </div>
</template>

<script>
  import {mapState, mapGetters} from 'vuex'
  import CartMode from '../CartMode';
  import AddCartForProce from '../AddCartForProce/index'
  import AddCartForFoodProce from '../AddCartForProce/forFoods'
  import {translateDetailData, getLastStockCountNum} from '@/utils/TranslateDetailDate';
  import getConfig from '@/utils/CJY/getConfig';

  export default {
    data() {
      return {
        workingInfo: null,
        commodityInfo: '',
        isFoodMode:false
      }
    },
    components: {CartMode, AddCartForProce,AddCartForFoodProce},
    created() {
      window.PSEvent.one('addCartForSpec', (data) => {
        console.log(data,'data=====data')
        this.isFoodMode = data.isFoodMode ? data.isFoodMode : false
        var config = {
          commodityInfo:data.commodityInfo,
          processList:data.processList
        }
        this.changeDetailInfo(config)
      })
    },
    methods: {
      translateDetailData,
      changeDetailInfo({commodityInfo}) {
        this.commodityInfo = commodityInfo
        this.showCartModal()
      },
      // 弹出弹出框
      async showCartModal() {
        if (this.storeConfigStatus == 'loaded') {
        } else if (this.storeConfigStatus == 'loading') {
          return
        } else {
          await getConfig()
          if (this.storeConfigStatus != 'loaded') {
            return
          }
        }
        var islocal = (/^localhost:8082+/gi).test(location.host) || this.goodsTrolleyType
        var isXiangpu = navigator.userAgent.indexOf("xiangpu") > -1;         //判断是否在象谱内打开
        if (!isXiangpu && !islocal) {
          location.href = location.href.split('H5')[0] + 'download/index.html';
          return
        }
        this.isFoodMode ? this.$refs.cartFoodModle && this.$refs.cartFoodModle.showModle() : 
        this.$refs.cartModle && this.$refs.cartModle.showModle();   
      },

      updateCart() {
       this.isFoodMode ? this.$refs.addCartForFoodProce && this.$refs.addCartForFoodProce.updateCart() :
       this.$refs.addCartForProce && this.$refs.addCartForProce.updateCart()
      },
      hideShade() {
        this.isFoodMode ? this.$refs.cartFoodModle.isShow = false : this.$refs.cartModle.isShow = false
      }
    },

    mounted() {
    },
    computed: {
      ...mapGetters({
        userInfo: 'xhModules/userInfo',
        sessionId: 'xhModules/sessionId',
      }),
      ...mapGetters(['cartConfig', 'storeConfigStatus']),
      goodsTrolleyType() {
        var getConfigParams = this.cartConfig || {}
        return getConfigParams.goodsTrolleyType || 0
      },
    }
  }
</script>

<style>

</style>
